﻿using BDShop.DAL;
using BDShop.Entities;
using System;
using System.Collections.Generic;
using IsolationLevel = System.Transactions.IsolationLevel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BDShop.Business
{
    public class OrderDetailService
    {
        public static long Insert(OrderDetail orderDetail)
        {
            try
            {
                using (var context = new BDShopEntities(IsolationLevel.ReadCommitted))
                {
                    context.OrderDetails.Add(orderDetail);

                    context.SaveChanges();
                    return orderDetail.ID;
                }
            }
            catch (Exception)
            {
                return -1;
            }
        }

        public static List<OrderDetail> GetByOrderID(long orderID)
        {
                using (var context = new BDShopEntities(IsolationLevel.ReadCommitted))
                {
                    return context.OrderDetails.Where(o=>o.OrderID==orderID).ToList();
                }
        }
    }
}
